/**
 * 初始化教师管理详情对话框
 */
var OrgTeacherInfoDlg = {
    orgTeacherInfoData : {}
};

/**
 * 清除数据
 */
OrgTeacherInfoDlg.clearData = function() {
    this.orgTeacherInfoData = {};
}

OrgTeacherInfoDlg.getClass = function(){
        obj = document.getElementsByName("test");
        check_val = [];
        for(k in obj){
            if(obj[k].checked)
                check_val.push(obj[k].value);
        }

        alert(check_val);
}
/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
OrgTeacherInfoDlg.set = function(key, val) {
    this.orgTeacherInfoData[key] = (typeof value == "undefined") ? $("#" + key).val() : value;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
OrgTeacherInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
OrgTeacherInfoDlg.close = function() {
    parent.layer.close(window.parent.OrgTeacher.layerIndex);
}

/**
 * 收集数据
 */
OrgTeacherInfoDlg.collectData = function() {
    this.set('id').set('infoId').set('classId').set('teacherName').
    set('teacherAge').set('teacherSex').set('teacherPic').set('teacherPic1').set('teacherPic2').set('teacherInfo').set('path');
}
OrgTeacherInfoDlg.getClassName = function() {

}
OrgTeacherInfoDlg.getInfoId = function(){
    layer.prompt({title: '输入任何口令，并确认', formType: 1}, function(pass, index){
        layer.close(index);
        layer.prompt({title: '随便写点啥，并确认', formType: 2}, function(text, index){
            layer.close(index);
            layer.msg('演示完毕！您的口令：'+ pass +'<br>您最后写下了：'+text);
        });
    });

}
/**
 * 提交添加
 */
OrgTeacherInfoDlg.addSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/orgTeacher/add", function(data){
        Feng.success("添加成功!");
        window.parent.OrgTeacher.table.refresh();
        OrgTeacherInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.orgTeacherInfoData);
    ajax.start();
}
OrgTeacherInfoDlg.addAdminSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/orgTeacher/addAdmin", function(data){
        Feng.success("添加成功!");
        window.parent.OrgTeacher.table.refresh();
        OrgTeacherInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.orgTeacherInfoData);
    ajax.start();
}



/**
 * 选择课程
 */
OrgTeacherInfoDlg.chooseClass = function(type) {

    // type 1表示复选  2 表示单选
    layer.open({
        type: 2,
        index:1,
        title: '选择课程',
        shade: 0,
        btn: ['确定','取消'],
        maxmin: true,
        shadeCloset:true,
        skin:'layui-layer-lan',
        area: ['393px', '300px'],
        yes: function(index,layero){
            //获取选中数据
            var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
            //调用授权提交方法
            var ids = iframeWin.getCheckAdIds();
            layer.close(index);
            $("#classId").val(ids);
            //获取翻译名称
            $.ajax({
                type: "post",
                dataType: "json",
                data: {ids:ids},
                url: "/orgClassType/getClassName" ,
                success: function (result) {
                    $("#classes").val(result);
                },
                error : function() {
                    layer.msg("系统繁忙，请稍后再试");
                }
            });
        },
        btn2: function (index) {
            //按钮【按钮二】的回调
            layer.close(index);
        },
        content: Feng.ctxPath + '/orgClass/chooseClass?type='+type,
    });
}




OrgTeacherInfoDlg.openPageLayer = function (){
//页面层
    layer.open({
        type: 2,
        index:1,
        title: '选择课程',
        shade: 0,
        btn: ['确定','取消'],
        maxmin: true,
        shadeCloset:true,
        skin:'layui-layer-lan',
        area: ['393px', '300px'],
        yes: function(index,layero){
            //获取选中数据
            var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
            //调用授权提交方法
            var ids = iframeWin.getCheckAdIds();
            layer.close(index);
            $("#classId").val(ids);
            //获取翻译名称
            $.ajax({
                type: "post",
                dataType: "json",
                data: {ids:ids},
                url: "/orgClassType/getClassName" ,
                success: function (result) {
                    $("#classes").val(result);
                },
                error : function() {
                    layer.msg("系统繁忙，请稍后再试");
                }
            });
        },
        btn2: function (index) {
            //按钮【按钮二】的回调
            layer.close(index);
        },
        content: Feng.ctxPath + '/orgTeacher/chooseClass',
    });

}
/**
 * 提交修改
 */
OrgTeacherInfoDlg.editSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/orgTeacher/update", function(data){
        Feng.success("修改成功!");
        window.parent.OrgTeacher.table.refresh();
        OrgTeacherInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.orgTeacherInfoData);
    ajax.start();
}







$(function() {
    var teacherPicUp = new $WebUpload("teacherPic",Feng.ctxPath + '/orgTeacher/upload');
    var teacherPicUp1 = new $WebUpload("teacherPic1",Feng.ctxPath + '/orgTeacher/upload');
    var teacherPicUp2 = new $WebUpload("teacherPic2",Feng.ctxPath + '/orgTeacher/upload');
    teacherPicUp.init();
    teacherPicUp1.init();
    teacherPicUp2.init();
});
